package com.stus.dao.impl;

import com.stus.dao.UsersDao;
import com.stus.mapper.UsersMapper;
import com.stus.model.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UsersDaoImpl implements UsersDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UsersMapper usersMapper;
    @Override
    public List<Users> listUsers() {
        String sql = "SELECT * FROM ssm_users";
        return jdbcTemplate.query(sql,usersMapper);
    }

    @Override
    public Users findUserByName(String username) {
        String sql = "SELECT * FROM ssm_users WHERE username = ?";
        return jdbcTemplate.queryForObject(sql, new Object[]{username}, usersMapper);
    }

}
